#include "mythtv/mythcontext.h"

#include <unistd.h>

#include "globalsettings.h"
#include <qfile.h>
#include <qdialog.h>
#include <qcursor.h>
#include <qdir.h>
#include <qimage.h>
#include <qstringlist.h>
#include <qprocess.h>
#include <qapplication.h>
#include <mythtv/util.h>

// General Settings

static HostLineEdit *SetAudioDirectory()
{
   HostLineEdit *gc = new HostLineEdit("MythAudio.Store");
   gc->setLabel(QObject::tr("Directory to hold audio files"));
   gc->setValue("/mnt/audio/");
   gc->setHelpText(QObject::tr("This directory must exist, and the user "
                               "running MythAudio needs to have read permission "
                               "to the directory."));
   return gc;
};

static HostComboBox *MusicAudioDevice()
{
   HostComboBox *gc = new HostComboBox("MythAudio.Device", true);
   gc->setLabel(QObject::tr("Audio device"));
   gc->addSelection(QObject::tr("default"), "default");
   QDir dev("/dev", "dsp*", QDir::Name, QDir::System);
   gc->fillSelectionsFromDir(dev);
   dev.setNameFilter("adsp*");
   gc->fillSelectionsFromDir(dev);

   dev.setNameFilter("dsp*");
   dev.setPath("/dev/sound");
   gc->fillSelectionsFromDir(dev);
   dev.setNameFilter("adsp*");
   gc->fillSelectionsFromDir(dev);
   gc->setHelpText(QObject::tr("Audio Device used for playback. 'default' will use the device specified in MythTV"));
   return gc;
};

static HostCheckBox *KeyboardAccelerators()
{
   HostCheckBox *gc = new HostCheckBox("MythAudio.KeyboardAccelerators");
   gc->setLabel(QObject::tr("Use Keyboard/Remote Accelerated Buttons"));
   gc->setValue(true);
   gc->setHelpText(QObject::tr("If this is not set, you will need "
                               "to use arrow keys to select and activate "
                               "various functions."));
   return gc;
};

//Player Settings

static HostComboBox *PlayMode()
{
   HostComboBox *gc = new HostComboBox("MythAudio.PlayMode");
   gc->setLabel(QObject::tr("Play mode"));
   gc->addSelection(QObject::tr("Normal"), "Normal");
   gc->addSelection(QObject::tr("Random"), "Random");
   gc->addSelection(QObject::tr("Intelligent"), "Intelligent");
   gc->setHelpText(QObject::tr("Starting shuffle mode for the player.  Can be "
                               "either normal, random, or intelligent (random)."));
   return gc;
};

static HostSlider *VisualModeDelay()
{
   HostSlider *gc = new HostSlider("MythAudio.VisualModeDelay", 0, 100, 1);
   gc->setLabel(QObject::tr("Delay before Visualizations start (seconds)"));
   gc->setValue(0);
   gc->setHelpText(QObject::tr("If set to 0, visualizations will never "
                               "automatically start."));
   return gc;
};

static HostSpinBox *VisualScaleWidth()
{
   HostSpinBox *gc = new HostSpinBox("MythAudio.VisualScaleWidth", 1, 2, 1);
   gc->setLabel(QObject::tr("Width for Visual Scaling"));
   gc->setValue(1);
   gc->setHelpText(QObject::tr("If set to \"2\", visualizations will be "
                               "scaled in half.  Currently only used by "
                               "the goom visualization.  Reduces CPU load "
                               "on slower machines."));
   return gc;
};

static HostSpinBox *VisualScaleHeight()
{
   HostSpinBox *gc = new HostSpinBox("MythAudio.VisualScaleHeight", 1, 2, 1);
   gc->setLabel(QObject::tr("Height for Visual Scaling"));
   gc->setValue(1);
   gc->setHelpText(QObject::tr("If set to \"2\", visualizations will be "
                               "scaled in half.  Currently only used by "
                               "the goom visualization.  Reduces CPU load "
                               "on slower machines."));
   return gc;
};

static HostLineEdit *VisualizationMode()
{
   HostLineEdit *gc = new HostLineEdit("MythAudio.VisualMode");
   gc->setLabel(QObject::tr("Visualizations"));
   gc->setValue("Random");
   gc->setHelpText(QObject::tr("List of visualizations to use during playback. "
                               "Possible values are space-separated list of ") + "Random, "
                   "MonoScope, StereoScope, Spectrum, BumpScope, Goom, "
                   "Synaesthesia, AlbumArt, Gears, Squares " + QObject::tr("and") +
                   " Blank");
   return gc;
};

AudioGeneralSettings::AudioGeneralSettings()
{
   VerticalConfigurationGroup* general = new VerticalConfigurationGroup(false);
   general->setLabel(QObject::tr("General Settings"));
   general->addChild(SetAudioDirectory());
   general->addChild(MusicAudioDevice());
   general->addChild(KeyboardAccelerators());
   addChild(general);
}

AudioPlayerSettings::AudioPlayerSettings()
{
   VerticalConfigurationGroup* playersettings = new VerticalConfigurationGroup(false);
   playersettings->setLabel(QObject::tr("Visualization Settings"));
   playersettings->addChild(VisualizationMode());
   playersettings->addChild(VisualModeDelay());
   playersettings->addChild(VisualScaleWidth());
   playersettings->addChild(VisualScaleHeight());
   addChild(playersettings);
}
